package com.hawthorn.mq.service.syslogjob.impl;

import com.hawthorn.mq.repository.SysLogJobMapper;
import com.hawthorn.mq.service.syslogjob.SysLogJobService;
import com.hawthorn.platform.model.po.SysJobLogPO;
import com.hawthorn.platform.redis.RedisMyClient;
import com.hawthorn.platform.utils.common.MyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;

@Service
public class SysLogJobServiceImpl implements SysLogJobService
{
  @Autowired
  private SysLogJobMapper sysLogjobMapper;
  @Autowired
  private RedisMyClient redisMyClient;

  @Override
  public void saveLogJob(Map<String, Object> param)
  {
    SysJobLogPO sysJobLogPO = new SysJobLogPO();
    sysJobLogPO.setJobId(Long.valueOf(MyUtil.getValue(param.get("jobId"))));
    sysJobLogPO.setJobName(MyUtil.getValue(param.get("jobName")));
    sysJobLogPO.setBeanName(MyUtil.getValue(param.get("beanName")));
    sysJobLogPO.setMethodName(MyUtil.getValue(param.get("methodName")));
    sysJobLogPO.setParams(MyUtil.getValue(param.get("params")));
    sysJobLogPO.setCronExpression(MyUtil.getValue(param.get("cronExpression")));
    sysJobLogPO.setIsSuccess(Integer.valueOf(MyUtil.getValue(param.get("isSuccess"))));
    sysJobLogPO.setExceptionDetail(MyUtil.getValue(param.get("exceptionDetail")));
    sysJobLogPO.setTime(Long.valueOf(MyUtil.getValue(param.get("time"))));
    sysJobLogPO.setCreateTime(LocalDateTime.now());
    if (!"".equals(MyUtil.getValue(param.get("bizType"))))
      sysJobLogPO.setBizType(Integer.valueOf(MyUtil.getValue(param.get("bizType"))));

    sysLogjobMapper.save(sysJobLogPO);
  }
}
